package com.jiayu.wheel.filter;

import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 过滤器demo
 * 多用于参数过滤，防SQL注入，防页面攻击，为空参数矫正，Token验证，session验证，点击率统计等
 * 配置完filter以后启动类里需要加@ServletComponentScan注解才能生效
 * Order越小过滤越靠前
 * @author Administrator
 */
@Order(1)
@WebFilter(urlPatterns = "/*")
public class FilterDemo implements Filter

{
    @Override
    public void init(FilterConfig filterConfig){
//        服务器启动时调用
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("==========>过滤器FilterDemo过滤Order=1");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
//        服务器关闭时调用
    }
}
